<?php
class WjbqjxAction extends UserAction{

    public function _initialize(){

        parent::_initialize();

    }


    public function info(){

        $id = $_GET['id'];

        $res = M('wjbqjx_user')->where(array('id'=>$id))->find();

        $this->assign('user',$res);

        $this->display();
    }

    public function index(){

        $users = M('wjbqjx_user')->select();

        $this->assign('users',$users);



        $this->display();
    }

    /**
     * 千家行 好项目
     */
    public function gooditem(){

        $items = M("wjbqjx_item")->select();

        $this->assign('items',$items);

        $this->display();
    }

    public function iteminfo(){

        if( isset($_GET['id']) ){

            $item = M('wjbqjx_item')->where(array('id'=>$_GET['id']))->find();
            //$item['commoninfo'] = unserialize($item['commoninfo']);

            $this->assign( 'item', $item );
            $this->display();

        }else{

            $this->error('处错误了');
        }
    }

    /**
     * 设置项目失效时间
     */
    public function setitemtime(){
        if(isset($_GET['id'])&&isset($_GET['date'])){
            $id = $_GET['id'];
            $date = $_GET['date'];
        }else{
            exit("0");
        }

        $validtime = strtotime($date);

        M('wjbqjx_item')->where(array('id'=>$id))->save(array('validtime'=>$validtime));
        exit("1");
    }

    /**
     * ajax审核函数
     */
    public function opp(){

        if(isset($_GET['type']) && isset($_GET['id']) ){
            if($_GET['type'] == 'verify'){
                M('wjbqjx_item')->where(array('id'=>$_GET['id']))->save(array('status'=>1));
                exit("审核成功");
            }else if($_GET['type'] == 'cancel'){
                M('wjbqjx_item')->where(array('id'=>$_GET['id']))->save(array('status'=>0));
                exit("取消成功");
            }
        }

    }

    /**
     * 审核千家行商家
     */
    public function oppcompany(){
        $id = $_GET['id'];
        $token = $_GET['token'];
        $type = $_GET['type'];

        if(!$id || !$token || !$type){
            exit("0");
        }
        if($type == 'verify'){
            M('wjbqjx_user')->where(array('id'=>$id,'token'=>$token))->save(array('status'=>1));
            exit("1");
        }else if( $type == 'cancel'){
            M('wjbqjx_user')->where(array('id'=>$id,'token'=>$token))->save(array('status'=>0));
            exit("1");
        }
    }


    public function  gq(){
        $gq = M('wjbqjx_gq')->where(array('pid'=>0))->select();

        $this->assign('gq',$gq);

        $this->display();
    }

    /**
     * 供求信息详情
     */
    public function gqinfo(){

        $id = $_GET['id'];

        $gqinfo = M('wjbqjx_gq')->where(array('id'=>$id))->find();

        $this->assign('gqinfo',$gqinfo);

        $replyinfo = M('wjbqjx_gq')->where(array('pid'=>$gqinfo['id']))->select();

        $this->assign('replyinfo',$replyinfo);

        $this->display();
    }


    /**
     * 千家行成员的配置设置的设置
     */
    public function set(){
        if( isset($_GET['do']) && $_GET['do'] == 'submit' ){
            $type = $_GET['type'];
            $jsonConfig= $_POST['config'];
            $jsonConfig = htmlspecialchars_decode( $jsonConfig );

            $config = json_decode($jsonConfig);

            $config = serialize($config);

            M('wjbconfig')->where(array('ckey'=>$type))->save(array('cvalue'=>$config));
            exit("1");

        }else {
            $configList = array('qjxresource', 'qjxpost', 'qjxfrom', 'qjxindustry');

            $type = $_GET['type'];
            if (in_array($type, $configList)) {
                $res = M('wjbconfig')->where(array('ckey' => $type))->find();
            } else {
                $this->error("页面出错");
            }

            $res['cvalue'] = unserialize($res['cvalue']);
            $this->assign('type', $type);
            $this->assign('qjxconfig', $res);
            $this->display();
        }
    }


    /**
     * 删除项目
     */
    public function del(){

        if(isset($_GET['id'])){
            $id = intval($_GET['id']);
        }else{
            exit("2");
        }

        M('wjbqjx_item')->where(array('id'=>$id))->delete();
        exit("1");
    }

    /**
     * 删除会员
     */
    public function qjxdel(){
        if(isset($_GET['id'])){
            $id = intval($_GET['id']);
        }else{
            exit("2");
        }

        M('wjbqjx_user')->where(array('id'=>$id))->delete();
        exit("1");
    }

    public function gqdel(){
        if(isset($_GET['id'])){
            $id = intval($_GET['id']);
        }else{
            exit("2");
        }

        M('wjbqjx_gq')->where(array('id'=>$id))->delete();
        exit("1");
    }
}